package vista;

import java.awt.BorderLayout;
import java.awt.List;

import javax.swing.DefaultListModel;
import javax.swing.JPanel;
import javax.swing.JInternalFrame;
import java.awt.Dimension;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.rmi.RemoteException;
import java.util.Vector;

import javax.swing.JList;

import modelo.NegocioRestaurant;
import modelo.Producto;

import javax.swing.JTextArea;

public class MostrarPedidos extends JInternalFrame {

	private JPanel jContentPane = null;
	private JButton refresh = null;
	private JButton Salir = null;
	private JList pedidos = null;
	private JTextArea jTextArea = null;
	private DefaultListModel modelo=new DefaultListModel();
	
	/**
	 * This is the xxx default constructor
	 */
	public MostrarPedidos() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(438, 293);
		this.setTitle("Mostrar los Pedidos");
		this.setContentPane(getJContentPane());
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getRefresh(), null);
			jContentPane.add(getSalir(), null);
			jContentPane.add(getPedidos(), null);
		}
		return jContentPane;
	}

	

	/**
	 * This method initializes refresh	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getRefresh() {
		if (refresh == null) {
			refresh = new JButton();
			refresh.setBounds(new Rectangle(50, 190, 120, 40));
			refresh.setText("Actualizar");
			refresh.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					NegocioRestaurant negocio = null;
					try {
						negocio = new NegocioRestaurant();
					} catch (RemoteException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					Vector<Producto> ped = negocio.getPedidosTotal();
					for(int i=0; i<ped.size(); i++){
					    modelo.addElement(ped.get(i));
					}
					pedidos.setModel(modelo);
				}
			});
		}
		return refresh;
	}

	/**
	 * This method initializes Salir	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getSalir() {
		if (Salir == null) {
			Salir = new JButton();
			Salir.setBounds(new Rectangle(240, 190, 120, 40));
			Salir.setText("Salir");
			Salir.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					dispose();
				}
			});
		}
		return Salir;
	}

	/**
	 * This method initializes pedidos	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getPedidos() {
		if (pedidos == null) {
			pedidos = new JList();
			pedidos.setBounds(new Rectangle(88, 25, 243, 140));
		}
		return pedidos;
	}

	
	public Vector<Producto> getPedidosTotal() {
		NegocioRestaurant negocio = null;
		try {
			negocio = new NegocioRestaurant();
		} catch (RemoteException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Vector<Producto> pedidos = negocio.getPedidosTotal();
		return pedidos;
}
	
	
	
	
	
}  //  @jve:decl-index=0:visual-constraint="10,10"
